package practice.annotaion.spring.door;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import practice.annotaion.spring.entrance.AlarmDevice;
import practice.annotaion.spring.entrance.AlarmDeviceSms;
import practice.annotaion.spring.entrance.Camera;
import practice.annotaion.spring.entrance.DisplayStrategy;
import practice.annotaion.spring.entrance.DisplayStrategyDefault;
import practice.annotaion.spring.entrance.HomeController;
import practice.annotaion.spring.entrance.InfraredRaySensor;
import practice.annotaion.spring.entrance.Recorder;
import practice.annotaion.spring.entrance.Viewer;
import practice.annotaion.spring.entrance.ViewerMonitor;

//  빈  사용  환경  선언
@Configuration
public class Config {

	// 새로운 빈 객체 제공
	@Bean
	public Camera camera1() {
		return new Camera();
	}

	@Bean
	public Camera camera2() {
		return new Camera();
	}

	@Bean
	public Camera camera3() {
		return new Camera();
	}

	@Bean
	public Camera camera4() {
		return new Camera();
	}

	@Bean
	public InfraredRaySensor windowSensor() {
		return new InfraredRaySensor("창 센서");
	}

	@Bean
	public InfraredRaySensor doorSensor() {
		return new InfraredRaySensor("문 센서");
	}

	@Bean
	public InfraredRaySensor lampSensor() {
		return new InfraredRaySensor("등 센서");
	}

	@Bean
	public AlarmDevice alarmDevice() {
		return new AlarmDeviceSms();
	}

	@Bean
	public Viewer viewer() {
		ViewerMonitor viewer = new ViewerMonitor();
		// 메서드 호출로 의존 관계 설정
		viewer.setDisplayStrategy(displayStrategy());
		return viewer;
	}

	@Bean
	public DisplayStrategy displayStrategy() {
		return new DisplayStrategyDefault();
	}

	@Bean
	@Qualifier("main")
	public Recorder recorder() {
		return new Recorder();
	}

	@Bean(initMethod = "init")
	public HomeController homeController() {
		HomeController homeController = new HomeController();
		List<InfraredRaySensor> sensors = new ArrayList<InfraredRaySensor>();
		sensors.add(windowSensor());
		sensors.add(doorSensor());
		homeController.setSensors(sensors);
		homeController.prepare(alarmDevice(), viewer());
		homeController.setCamera1(camera1());
		homeController.setCamera2(camera2());
		homeController.setCamera3(camera3());
		homeController.setCamera4(camera4());
		return homeController;
	}
}
